package com.ddwl.shop.dao;

import cn.hutool.core.util.StrUtil;
import com.ddwl.common.dao.TkDao;
import com.ddwl.shop.dao.mapper.ShopDistributionMapper;
import com.ddwl.shop.dao.model.ShopDistribution;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2021/5/6 13:57
 */
@Repository
public class ShopDistributionDao extends TkDao<ShopDistributionMapper, ShopDistribution> {


    @Resource
    private ShopDistributionMapper shopDistributionMapper;


    public ShopDistribution selectByShopId(String shopId) {
        if (StrUtil.isEmpty(shopId)) {
            return null;
        }
        ShopDistribution sd = new ShopDistribution();
        sd.setShopId(shopId);
        return selectOne(sd);
    }

    public List<ShopDistribution> selectByShopIds(List<String> shopIds) {
        Example example = getExample();
        example.and().andIn("shopId", shopIds);
        return shopDistributionMapper.selectByExample(example);
    }

    public void updateShopDistributionByShopId(ShopDistribution sd,String shopId) {
        Example example = getExample();
        example.and().andEqualTo("shopId", shopId);
        shopDistributionMapper.updateByExampleSelective(sd, example);
    }

    public List<ShopDistribution> getByShopIds(List<String> shopIds) {
        if (CollectionUtils.isEmpty(shopIds)) {
            return null;
        }
        Example example = getExample();
        example.and().andIn("shopId", shopIds);
        return shopDistributionMapper.selectByExample(example);
    }
}
